<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="封号类别" prop="limitType">
        <el-select v-model="queryParams.bannedType" placeholder="请选择封号类别" clearable>
          <el-option v-for="dict in dict.type.banned_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="sysIpDeviceBannedList">

      <el-table-column label="封禁类别" align="center" prop="bannedType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.banned_type" :value="scope.row.bannedType"/>
        </template>
      </el-table-column>
      <el-table-column label="封禁目标内容" align="center" prop="target"/>
      <el-table-column label="操作原因" align="center" prop="reason"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listSysIpDeviceBanned,
} from "@/api/service/sys/sysIpDeviceBanned";

export default {
  name: "SysIpDeviceBanned",
  dicts: ['limit_type', 'banned_type'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 封禁IP和设备记录表格数据
      sysIpDeviceBannedList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        platformId: undefined,
        bannedType: undefined
      },
      // 表单参数
      form: {},

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询封禁IP和设备记录列表 */
    getList() {
      this.loading = true;
      listSysIpDeviceBanned(this.queryParams).then(response => {
        this.sysIpDeviceBannedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /**
     * 点击用户爱动id跳转到用户页面
     * @param platformId
     */
    toUserInfo(platformId) {
      this.$router.push({path: "/user/appUser", query: {id: platformId}});
    }
  }
};
</script>
